package com.maud.dialog;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

import android.app.DatePickerDialog;
import android.content.Context;
import android.widget.DatePicker;

public class DatePickerDialogEncapsulation {
	private Calendar dateAndTime = Calendar.getInstance(Locale.CHINA);
	private OnDateOkListener listenter;
	private int flag;
	private DatePickerDialog.OnDateSetListener d = new DatePickerDialog.OnDateSetListener() {
		@Override
		public void onDateSet(DatePicker view, int year, int monthOfYear,
				int dayOfMonth) {
			dateAndTime.set(Calendar.YEAR, year);
			dateAndTime.set(Calendar.MONTH, monthOfYear);
			dateAndTime.set(Calendar.DAY_OF_MONTH, dayOfMonth);
			SimpleDateFormat faFormat = new SimpleDateFormat("yyyy-MM-dd");
			listenter.setDateToControl(flag, faFormat.format(dateAndTime.getTime()));
		}
	};
	
	public   DatePickerDialogEncapsulation(OnDateOkListener listener,int flag) {
		this.flag=flag;
		this.listenter=listener;
		new DatePickerDialog((Context)listener, d,
				dateAndTime.get(Calendar.YEAR),
				dateAndTime.get(Calendar.MONTH),
				dateAndTime.get(Calendar.DAY_OF_MONTH)).show();
	} 
	
}
